<template>
  <div class="in-wrap">
    <!-- 公共头引入 -->
    <header id="header">
      <client-only>
        <vue-particles
          color="#39AFFD"
          :particleOpacity="0.7"
          :particlesNumber="40"
          shapeType="circle"
          :particleSize="4"
          linesColor="#8DD1FE"
          :linesWidth="2"
          :lineLinked="true"
          :lineOpacity="0.4"
          :linesDistance="150"
          :moveSpeed="3"
          :hoverEffect="true"
          hoverMode="grab"
          :clickEffect="true"
          clickMode="push"
          class="cash"
        >
        </vue-particles>

      <section class="container">
        <el-backtop title="回到顶部" :buttom="100" >
          <div
            style="{
        height: 100%;
        width: 100%;
        background-color: #f2f5f6;
        box-shadow: 0 0 6px rgba(0,0,0, .12);
        text-align: center;
        line-height: 40px;
        color: #1989fa;
      }"
          >
            UP
          </div>
        </el-backtop>
        <h1 id="logo">
          <a href="/" title="P站">
            <img src="~/assets/img/logo.png" width="100%" alt="P站">
          </a>
        </h1>
        <div class="h-r-nsl">
          <ul class="nav">
            <router-link to="/index" tag="li" active-class="current" exact>
              <a>首页</a>
            </router-link>
            <router-link to="/course" tag="li" active-class="current">
              <a>作品</a>
            </router-link>
            <router-link to="/teacher" tag="li" active-class="current">
              <a>作者</a>
            </router-link>
            <router-link to="/login" tag="li" active-class="current">
              <a @click="go">论坛</a>
            </router-link>
            <router-link to="/qa" tag="li" active-class="current">
              <a>问答</a>
            </router-link>
          </ul>
         <!-- / nav -->
          <ul class="h-r-login">
              <li v-if="!loginInfo.id" id="no-login">
                  <a href="/login" title="登录">
                      <em class="icon18 login-icon">&nbsp;</em>
                      <span class="vam ml5">登录</span>
                  </a>
                  |
                  <a href="/register" title="注册">
                      <span class="vam ml5">注册</span>
                  </a>
              </li>
              <li v-if="loginInfo.id" id="is-login-one" class="mr10">
                  <a id="headerMsgCountId" href="#" title="消息">
                      <em class="icon18 news-icon">&nbsp;</em>
                  </a>
                  <q class="red-point" style="display: none">&nbsp;</q>
              </li>
              <li v-if="loginInfo.id" id="is-login-two" class="h-r-user">
                  <a href="/ucenter" title>
                      <img :src="loginInfo.avatar" width="30" height="30" class="vam picImg" :alt="loginInfo.nickname">
                      <span id="userName" class="vam disIb">{{ loginInfo.nickname }}</span>
                  </a>
                  <a href="javascript:void(0);" title="退出" @click="logout()" class="ml5">退出</a>
              </li>
              <!-- /未登录显示第1 li；登录后显示第2，3 li -->
          </ul>
          <aside class="h-r-search">
            <form action="#" method="post">
              <label class="h-r-s-box">
                <input type="text" placeholder="输入你想看的番剧" name="queryCourse.courseName" value>
                <button type="submit" class="s-btn">
                  <em class="icon18">&nbsp;</em>
                </button>
              </label>
            </form>
          </aside>
        </div>
        <aside class="mw-nav-btn">
          <div class="mw-nav-icon"></div>
        </aside>
        <div class="clear"></div>
      </section>
      </client-only>
    </header>

    <!-- /公共头引入 -->
    <nuxt/>

    <!-- 公共底引入 -->
    <footer id="footer">
      <section class="container">
        <div class>
          <h4 class="hLh30">
            <span class="fsize18 f-fM c-999">友情链接</span>
          </h4>
          <ul class="of flink-list">
            <li>
              <a href="http://www.baidu.com/" title="百度" target="_blank">百度</a>
            </li>
          </ul>
          <div class="clear"></div>
        </div>
        <div class="b-foot">
          <section class="fl col-7">
            <section class="mr20">
              <section class="b-f-link">
                <a href="#" title="关于我们" target="_blank">关于我们</a>|
                <a href="#" title="联系我们" target="_blank">联系我们</a>|
                <a href="#" title="帮助中心" target="_blank">帮助中心</a>|
                <a href="#" title="资源下载" target="_blank">资源下载</a>|
                <span>服务热线：010-56253825(北京) 0755-85293825(深圳)</span>
                <span>Email：info@pilipili.com</span>
              </section>
              <section class="b-f-link mt10">
                <span>©本站版权均归P站所有 资源如有雷同纯属巧合 京ICP备17055252号</span>
              </section>
            </section>
          </section>
          <aside class="fl col-3 tac mt15">
            <section class="gf-tx">
              <span>
                <img src="~/assets/img/wx-icon.png" alt>
              </span>
            </section>
            <section class="gf-tx">
              <span>
                <img src="~/assets/img/wb-icon.png" alt>
              </span>
            </section>
          </aside>
          <div class="clear"></div>
        </div>
      </section>
    </footer>
    <!-- /公共底引入 -->
  </div>
</template>
<script>

import "~/assets/css/reset.css";
import "~/assets/css/theme.css";
import "~/assets/css/global.css";
import "~/assets/css/web.css";
import cookie from 'js-cookie'
import userApi from '@/api/login'
export default {
  data() {
    return {
      token: '',
      loginInfo: {
        id: '',
        age: '',
        avatar: '',
        mobile: '',
        nickname: '',
        sex: ''
      }
    }
  },

  created() {
    this.token = this.$route.query.token
    if (this.token) {
      this.wxLogin()
    }
    this.showInfo()
  },

  methods: {
    //从cookie获取用户信息(字符串)转为JSON对象(去掉字符串外的双引号)
    showInfo() {
      const jsonStr = cookie.get("ucenter");
      if (jsonStr) {
        this.loginInfo = JSON.parse(jsonStr)
      }
    },
    //退出登录=清空cookie内的值,然后返回首页
    logout() {
      cookie.set('ucenter', "", {domain: 'localhost'})
      cookie.set('token', "", {domain: 'localhost'})
      window.location.href = "/"
    },
    //微信登录
    wxLogin() {
      if (this.token === '') return
      //把token存在cookie中、也可以放在localStorage中
      cookie.set('token', this.token, {domain: 'localhost'})
      cookie.set('ucenter', '', {domain: 'localhost'})
      //登录成功根据token获取用户信息
      userApi.getUserInfo().then(response => {
        this.loginInfo = response.data.data.userInfo
        //将用户信息记录cookie
        cookie.set('ucenter', this.loginInfo, {domain: 'localhost'})
      })
    },
    go(){
      window.location.href="http://unlimite.cn/"
    }
  }
}
</script>
<style>
  .cash {
    position:absolute;
    top:100px;
    height: 400px;
    width:100%;
  }
</style>

